package com.koko.controller;

import com.koko.result.Result;
import com.koko.service.UserService;
import com.koko.user.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取登录用户的信息
     * @return
     */
    @GetMapping("/userInfo")
    public Result<UserVO> getUserInfo() {
        return Result.success(userService.getUserInfo());
    }

    /**
     * 获取好友列表
     * @param usernameOrNickname
     * @return
     */
    @GetMapping("/friends")
    public Result<List<UserVO>> getFriendsList(@RequestParam(required = false) String usernameOrNickname) {
        return Result.success(userService.getFriendsList(usernameOrNickname));
    }

    /**
     * 通过id获取用户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserVO> getUserById(@PathVariable Long id) {
        return Result.success(userService.getUserById(id));
    }

    /**
     * feign扣款接口
     * @param toPay 扣款金额
     * @return
     */
    @PostMapping("/pay")
    public Result<String> pay(@RequestBody String toPay) {
        userService.pay(new BigDecimal(toPay));
        return Result.success();
    }
}
